package org.meow.controller.api;

import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.meow.dto.ArticlePageDTO;
import org.meow.entity.Article;
import org.meow.result.Result;
import org.meow.service.ArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * &#064;Date: 24/05/16-13:48
 * &#064;Description:
 */
@RestController
@RequestMapping("/api/article")
@Tag(name = "API接口")
public class ArticleApi {

  @Autowired
  private ArticleService articleService;

  @GetMapping("/{cateId}")
  @Operation(summary = "获取分类id下的文章列表")
  public Result<List<Article>> getArticleById(@PathVariable Integer cateId) {
    return Result.success(articleService.getArticlesByCateId(cateId));
  }

  @PostMapping
  @Operation(summary = "获取分类id下的文章列表分页")
  public Result<IPage<Article>> getArticlePageById(@RequestBody ArticlePageDTO articlePageDTO) {
    IPage<Article> pageResult = articleService.pageQuery(articlePageDTO);
    return Result.success(pageResult);
  }

}
